﻿using Bangle.SerialPort;
using Bangle.SerialPort.Messages;
using System;
using System.Threading.Tasks;

namespace Eglober.Abp.SerialPort.ConsoleTestApp.Services
{
    [SerialPort("Test")]
    public class TestSerialPortService : AbstractAbpSerialPortService<ASCIIStringMessage>
    {
        public override async Task OnOpenAsync(System.IO.Ports.SerialPort serialPort)
        {
            for (var i = 0; i < 100; i++)
            {
                serialPort.WriteLine(DateTime.Now.ToString());
                await Task.Delay(1000 * 3);
            }
        }

        protected override Task OnDataReceived(ASCIIStringMessage msg)
        {
            Console.WriteLine("Text:{0}", msg);
            return Task.CompletedTask;
        }
    }
}
